package com.sport.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sport.entity.SysMenu;
import com.sport.entity.SysPermission;
import com.sport.mapper.SysMenuMapper;
import com.sport.service.SysMenuService;
import com.sport.utils.PageResult;
import com.sport.utils.QueryInfo;
import com.sport.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class SysMenuServiceImpl implements SysMenuService {
    @Autowired
    SysMenuMapper sysMenuMapper;

    /**
     * 查找父级所有菜单
     * @return
     */
    @Override
    public Result findParent() {
        return Result.success("查询父级菜单成功",sysMenuMapper.findParent());
    }

    @Override
    public Result findMenu(QueryInfo queryInfo) {
        log.info("开始权限分页:--->页面{},--->页数{},查询内容{}", queryInfo.getPageNumber(), queryInfo.getPageSize(), queryInfo.getQueryString());
        PageHelper.startPage(queryInfo.getPageNumber(), queryInfo.getPageSize());
        Page<SysMenu> page = sysMenuMapper.findMenu(queryInfo.getQueryString());
        long total = page.getTotal();
        List<SysMenu> result = page.getResult();
        log.info("查询的总条数---->{}", total);
        log.info("分页列表——-{}", result);
        return PageResult.pageResult(total, result);

    }

    @Override
    public Result insert(SysMenu sysMenu) {
        sysMenuMapper.insert(sysMenu);
        return Result.success("数据插入成功");
    }

    @Override
    public Result delete(Long id) {
        sysMenuMapper.delete(id);
        return Result.success("数据删除成功");
    }

    @Override
    public Result update(SysMenu sysMenu) {
        sysMenuMapper.update(sysMenu);
        return Result.success("数据修改成功");
    }

}

